using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter20
{
	/// <summary>
	/// Example06: An Isothermal Expansion
	/// A 1.0 mol sample of an ideal gas is kept at 0.0 C during
	/// an expansion from 3.0 L to 10.0 L.
	/// (A) How much work is done on the gas during the expansion?
	/// W = -2.7 \times 10^3 J
	/// (B) How much energy transfer by heat occurs with the 
	/// surroundings in this process?
	/// Q = -W = 2.7 \times 10^3 J
	/// (C) If the gas is returned to the orginal volume by means
	/// of an isobaric process, how much work is done on the gas?
	/// W = 1.6 \times 10^3 J
	/// </summary>
	public class Example06
	{
		public Example06()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.IdealGas gas = new L.IdealGas();
			gas.Mole = 1.0;
			L.Temperature t = new L.Temperature();
			t.C = 0.0;
			t.FindAbsoluteFromCelsius();
			gas.Temperature = t.K;
			//(A)
			L.Work W = new L.Work();
			W.J = - gas.Mole*L.Constant.UniversalGasConstant
				*gas.Temperature*Math.Log(10.0/3.0);
			result+=Convert.ToString(W.J)+"\r\n";     
			//(B)
			L.Energy U = new L.Energy();
			U.J = 0.0;
			L.Heat Q = new L.Heat();
			Q.VariableQ = true;
			L.FundamentalLaw.ThermodynamicsFirstLaw(Q,W,U);
			result+=Convert.ToString(Q.J)+"\r\n";    
			//(C)
			gas.Volume = 10.0E-3;
			gas.FindPressure();
			W.J = -gas.Pressure*(3.0E-3 - 10.0E-3);
			result+=Convert.ToString(W.J)+"\r\n";    
		}
	}
}
